package org.example.springbook.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Slf4j
@Aspect
//@Component
public class AspectDemo {
    @Pointcut("execution(* org.example.springbook.controller.*.*(..))")
    public void pt(){

    }
    @Before("execution(* org.example.springbook.controller.*.*(..))")
    public void doBefore(){

        log.info("AspectDemo执行doBefore");
    }
    @After("execution(* org.example.springbook.controller.*.*(..))")
    public void doAfter(){
        log.info("AspectDemo执行doAfter");
    }
    @AfterReturning("execution(* org.example.springbook.controller.*.*(..))")
    public void doAfterReturning(){
        log.info("AspectDemo执行doAfterReturning");
    }
    @AfterThrowing("execution(* org.example.springbook.controller.*.*(..))")
    public void doAfterThrowing(){
        log.info("AspectDemo执行doAfterThrowing");
    }
    @Around("execution(* org.example.springbook.controller.*.*(..))")
    public Object doAround(ProceedingJoinPoint jt){
        log.info("around 前处理");
        Object proceed=null;
        try {
            proceed=jt.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        log.info("around后处理");
        return proceed;
    }
}
